<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>2222</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<link href="/resources/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <script src="/resources/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <!-- <script src="/resources/lib/ligerUI/js/core/base.js" type="text/javascript"></script> -->
    <script src="/resources/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
    <script src="/resources/lib/ligerUI/js/plugins/ligerForm.js"></script>
    <script src="/resources/lib/ligerUI/js/plugins/ligerPopupEdit.js"></script>
   	<script src="/resources/lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script> 
    <script src="/resources/lib/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
    <script src="/resources/lib/jquery-validation/messages_cn.js" type="text/javascript"></script>
    <script src="/resources/lib/json2.js" type="text/javascript"></script>
    <script type="text/javascript">
    var dialog = frameElement.dialog; //调用页面的dialog对象(ligerui对象)
    var parentData = dialog.options.data;
    var action_type =  dialog.options.action_type;
    console.log(dialog);
   // window.parent.itemclick(null);//调用父窗口方法
    var form = null;
    $(function (){
           form = $("form").ligerForm({
                inputWidth: 170, labelWidth: 90, space: 40,
                validate: true,
                fields: [
                { name: "uuid", type: "hidden" },
                { display: "资源名称", name: "resourceName", newline: true, type: "text",validate:{ required: true,minlength:1} }, 
                { display: "是否菜单", name: "isMenu", newline: true, type: "checkbox" },
                { display: "是否子节点 ", name: "isLeaf", newline: true, type: "checkbox"},
                { display: "序列", name: "orderSign", newline: true, type: "spinner",options:{type:"int"}},
                { display: "菜单级别", name: "menuLevel", newline: true, type: "spinner",options:{type:"int"} },
                {
                    type: 'popup',id:'parentId', name: 'parentId', label: '父级菜单',textField:"parentName", editor: {
                    	onButtonClick :function(){
                    		//this.setValue('01');
                    		//this.setText("T1");
                    		//this.set({grid:getGridOptions(true)});
                    		//this.options.grid=getGridOptions(true);
                    		/* var d = new Date().getTime();
                    		this.options.grid.set({url:"/system/sysResourceJsonList?d="+d});
                    		this.options.grid.data=null; */
                    		//alert("click");
                    		/**
                    			保证每次点击能重新从后台加载数据
                    		*/
                    		var grid = $.ligerui.get('popSelectGrid_e');
                    		if(grid)grid.reload();
                    	},
                        condition: {
                            fields: [{ name: 'resourceName',type:'text', label: '资源名称' }]
                        },
                        grid: getGridOptions(true),
                        valueField: 'uuid',
                        textField: 'resourceName',
                        parms :{date:new Date().getTime()},
                        width: 300,
                        height:100
                    }
                },
                { display: "状态", name: "status", newline: true, type: "select",textField:"statusNamew",validate:{ required: true} ,
                	options:{/* columns:[{ header: 'ID', name: 'id', width: 80 },
                			 { header: '状态', name: 'desc', width: 170 }], */
                    data:[{id:1,desc:'正常'},{id:2,desc:'作废'}],valueField : 'id',textField: 'desc'}},
                { display: "url", name: "url", newline: true, type: "text",validate:{ required: true}  },
                { display: "备注", name: "Remark", newline: true, type: "text" ,width:470 }
                ],
                buttons :[
						{ text: '提交', click: submitForm}
                          ]
            }); 
           form.setData(parentData);
          // var pd = $.ligerui.get('parentId');
         //pd.setValue('01');
   		// pd.setText("T1");
           function getGridOptions(checkbox) {
               var options = {
            		   url:"/system/sysResourceJsonList",
            		   parms :{date:new Date().getTime()},
            		   id:"popSelectGrid_e",
            		   columns: [
            	                
            	                { display: "资源名称", name: "resourceName",  type: "text" ,align: 'left'}, 
            	                { display: "是否菜单", name: "isMenu",  type: "text" ,align: 'left',
            	                	render: function (item)
           	                     {
           	                         if (item.isMenu == "true") return '是';
           	                         return '否';
           	                     }},
            	                { display: "是否子节点 ", name: "isLeaf",  type: "text",align: 'left',
            	                	render: function (item)
              	                     {
              	                         if (item.isMenu == "true") return '是';
              	                         return '否';
              	                     }},
            	                { display: "序列", name: "orderSign",  type: "text",options:{type:"int"},align: 'left'},
            	                { display: "菜单级别", name: "menuLevel",  type: "text",options:{type:"int"} ,align: 'left'},
            	                /* { name: "parentId", type: "hidden"}, */
            	                { display: "状态", name: "status",  type: "text" ,align: 'left',
            	                	render: function (item)
            	                	                     {
            	                	                         if (item.status == 1) return '正常';
            	                	                         return '作废';
            	                	                     }
								},
            	                { display: "url", name: "url",  type: "text" ,align: 'left'}
            	                ], width: '100%', height: '97%',usePager  :false,
            	    onSelectRow: function (rowdata, rowindex)
            	                {
            	                   console.log(rowdata);
            	                },
            	    alternatingRow: false,
            	    tree: { columnName: 'resourceName' },
            	    autoCheckChildren: false
                  /*  data: $.extend({}, TreeDeptData) */
               };
               return options;
           }
        }); 
        
        function submitForm(){
        	 var data = form.getData(); 
        	 data.action_type = action_type;
 			if (form.valid())
             {
 				console.log(data);
 				$.ajax({
                    loading: '正在保存数据中...',
                    type:'post',
                    url: "/system/sysSaveResource",
                    data: data,
                    success: function (json) {
                    	console.log(json);
                    	 $.ligerDialog.success('提示内容');
                    },
                    error: function (message) {
                        alert(message);
                    }
                });
             }
             else
             {
                 form.showInvalid();
             } 
        }

    </script>
    <style type="text/css">
        .l-table-edit {}
        .l-table-edit-td{ padding:4px;}
        .l-button-submit,.l-button-reset{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
    </style>

</head>

<body style="padding:10px">
<div position="center" id="framecenter"> 
<form id="form2"></form> 
</div>
<div style="display:none">
     
</body>
</html>
